package Value类型

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object WordCount {

    def main(args: Array[String]): Unit = {

        val config: SparkConf = new SparkConf().setMaster("local[*]").setAppName("WordCount")

        val sc = new SparkContext(config)

        //默认查找位置依据部署方式
        //本地查找写法 ///software/spark-2.1.1/in
        val lines: RDD[String] = sc.textFile("in/words.txt")

        val words: RDD[String] = lines.flatMap(_.split(" "))

        val wordsToOne: RDD[(String, Int)] = words.map((_, 1))

        val wordToSum: RDD[(String, Int)] = wordsToOne.reduceByKey(_ + _)

        val tuples: Array[(String, Int)] = wordToSum.collect()

        tuples.foreach(println)
    }

}
